﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Crawsome
{
    public partial class CrawsomeMain : Form
    {
        /// <summary>
        /// Initialization of Main GUI Window
        /// </summary>
        public CrawsomeMain()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Start crawling
        /// </summary>
        private void btnCrawl_Click(object sender, EventArgs e)
        {
            string sURL = txtBoxURL.Text;

            lblStatus.Text = "Validating URL...";
            if (RegexMaster.isValidURL(sURL))
            {
                lblStatus.Text = "Valid URL.... Crawling...";
                string test = RequestMaster.GET(sURL);
                string[] links = RegexMaster.getAllLinks(test);
                foreach (string s in links)
                {
                    Log(s);
                }
            }
            else
            {
                lblStatus.Text = "Invalid URL.";
            }
        }

        public void Log(string text)
        {
            LogBox.AppendText(text + "\n");
        }

    }
}
